<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ex1.自定义事件</title>
</head>
<body>
    <div style="height: 200px;width: 100px;background-color: aqua;"></div>

    <script type="text/javascript">
        let div = document.querySelector('div')

        // 1. 定义一个 haha 事件
        const haha = new Event('haha')

        // 2. 给元素绑定 haha 事件，并设置回调函数
        div.addEventListener('haha', (event)=>{
            console.log('Event trigger!',event)
        })

        // 3. 元素触发 haha 事件，从而调用回调函数
        div.dispatchEvent(haha)
    </script>
</body>
</html>